package com.yc.favorite.biz;

import com.yc.favorite.entity.User;
import com.yc.favorite.mapper.UserMapper;
import com.yc.favorite.util.MyBatisHelper;
import com.yc.favorite.util.Utils;
import org.apache.ibatis.session.SqlSession;

public class UserBiz {
    public User login(String name, String pwd) throws BizException {
        Utils.checkEmpty(name, "账号不能为空!");
        Utils.checkEmpty(pwd, "密码不能为空!");
        try(SqlSession session = MyBatisHelper.openSession()){
            final UserMapper mapper = session.getMapper(UserMapper.class);
            final User user = mapper.selectForLogin(name, pwd);
            Utils.checkEmpty(user, "用户名或密码错误!");
            return user;
        }
    }
}
